
package com.zsrt.jmj.computer.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zsrt.jmj.computer.dao.ComputerDao;
import com.zsrt.jmj.computer.entity.ComputerEntity;
import com.zsrt.jmj.computer.service.ComputerService;
@Service
public class ComputerServiceImpl implements ComputerService {

	@Autowired
	private ComputerDao dao;
	@Override
	public void add(ComputerEntity entity, Map<String, Object> map) {
		//dao.add(entity);
		dao.insert(entity);
		map.put("result", "success");
		map.put("jieguo", "添加成功...");
	}
	@Transactional()
	@Override
	public void findAllComputers(Map<String, Object> map) {
		List<ComputerEntity> list = dao.findAll();
		//因为不是单表
		map.put("result", "success");
		map.put("jieguo", "查询成功...");
		map.put("data", list);
	}

	@Override
	public void updateById(ComputerEntity entity, Map<String, Object> map) {
		//dao.updateById(entity);
		dao.updateByPrimaryKey(entity);
		map.put("result", "success");
		map.put("jieguo", "修改成功...");

	}

	@Transactional(readOnly=true)
	@Override
	public void findComputerById(int id, Map<String, Object> map) {
		//因为不是单表
		ComputerEntity entity = dao.findById(id);
		map.put("result", "success");
		map.put("jieguo", "查询成功...");
		map.put("data", entity);
	}

	@Override
	public void deleteByIds(String ids, Map<String, Object> map) {
		String[] split = ids.split(",");
		for(String s:split){
			int id = Integer.parseInt(s);
			dao.deleteByPrimaryKey(id);
		}
		map.put("result", "success");
		map.put("jieguo", "成功...");

	}

}
